home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / DataSources / ColdFusion / Session.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  6.0 KB  |  239 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3.  
  4. //************** GLOBALS VARS *****************
  5.  
  6. var SESSION_FILENAME = "SES_D.gif";
  7. var DATASOURCELEAF_FILENAME = "DSL_D.gif";
  8.  
  9.  
  10. //****************** API **********************
  11.  
  12. //--------------------------------------------------------------------
  13. // FUNCTION:
  14. //   addDynamicSource
  15. //
  16. // DESCRIPTION:
  17. //   Adds a Dynamic Source to the Data Bindings panel
  18. //
  19. // ARGUMENTS:
  20. //   none
  21. //
  22. // RETURNS:
  23. //   nothing
  24. //--------------------------------------------------------------------
  25.  
  26. function addDynamicSource()
  27. {
  28.   MM.retVal = "";
  29.   MM.sessionContents = "";
  30.   dw.popupCommand("Session Variable");
  31.   if (MM.retVal == "OK")
  32.   {
  33.     var theResponse = MM.sessionContents;
  34.     if (theResponse.length)
  35.     {
  36.       var siteURL = dw.getSiteRoot();
  37.       if (siteURL.length)
  38.       {
  39.         dwscripts.addListValueToNote(siteURL, "Session", theResponse);   
  40.       }
  41.       else
  42.       {
  43.         alert(MM.MSG_DefineSite);
  44.       }
  45.     }
  46.     else 
  47.     {
  48.       alert(MM.MSG_DefineSession);
  49.     }
  50.   }
  51. }
  52.  
  53.  
  54. //--------------------------------------------------------------------
  55. // FUNCTION:
  56. //   findDynamicSources
  57. //
  58. // DESCRIPTION:
  59. //   Returns a list of Dynamic Sources on the page
  60. //
  61. // ARGUMENTS:
  62. //   none
  63. //
  64. // RETURNS:
  65. //   JavaScript Array of Objects
  66. //--------------------------------------------------------------------
  67.  
  68. function findDynamicSources()
  69. {
  70.   var retList = new Array();
  71.  
  72.   var siteURL = dw.getSiteRoot()
  73.  
  74.   if (siteURL.length)
  75.   {
  76.     var bindingsArray = dwscripts.getListValuesFromNote(siteURL, "Session");
  77.     if (bindingsArray.length > 0)
  78.     {
  79.       retList.push(new DataSource(MM.LABEL_Session, 
  80.                                   SESSION_FILENAME, 
  81.                                   false, 
  82.                                   "Session.htm"))
  83.     }
  84.   }
  85.  
  86.   return retList;
  87. }
  88.  
  89.  
  90. //--------------------------------------------------------------------
  91. // FUNCTION:
  92. //   generateDynamicSourceBindings
  93. //
  94. // DESCRIPTION:
  95. //   Returns a list of bindings for the given elementName on the page.
  96. //
  97. // ARGUMENTS:
  98. //   sourceName - string - the name returned from the findDynamicSources
  99. //     function
  100. //
  101. // RETURNS:
  102. //   JavaScript Array of Objects
  103. //--------------------------------------------------------------------
  104.  
  105. function generateDynamicSourceBindings(sourceName)
  106. {
  107.   var retVal = new Array();
  108.  
  109.   var siteURL = dw.getSiteRoot();
  110.  
  111.   //For localized object name
  112.   if (sourceName != "Session")
  113.   {
  114.     sourceName = "Session";
  115.   }
  116.  
  117.   if (siteURL.length)
  118.   {
  119.     var bindingsArray = dwscripts.getListValuesFromNote(siteURL, sourceName);
  120.     retVal = getDataSourceBindingList(bindingsArray, 
  121.                                       DATASOURCELEAF_FILENAME,
  122.                                       true,
  123.                                       "Session.htm");
  124.  
  125.     // Add the variable names to a code hints menu
  126.     dw.codeHints.resetMenu("CodeHints_Object_Methods", "Session.",
  127.       "ColdFusion");
  128.     if (bindingsArray.length > 0)
  129.       dw.codeHints.addMenu("CodeHints_Object_Methods","Session.",
  130.         bindingsArray, bindingsArray, "shared/mm/images/hintMisc.gif", 
  131.         "ColdFusion");
  132.   }
  133.  
  134.   return retVal;
  135. }
  136.  
  137.  
  138. //--------------------------------------------------------------------
  139. // FUNCTION:
  140. //   generateDynamicDataRef
  141. //
  142. // DESCRIPTION:
  143. //   Returns a dynamic binding string.
  144. //
  145. // ARGUMENTS:
  146. //   sourceName - string - the name of the dynamic source returned
  147. //     from the findDynamicSources function
  148. //   bindingName - string - the name of a dynamic source binding returned
  149. //     from generateDynamicSourceBindings
  150. //
  151. // RETURNS:
  152. //   string - the code to insert on the page
  153. //--------------------------------------------------------------------
  154.  
  155. function generateDynamicDataRef(sourceName, bindingName, dropObject)
  156. {
  157.   var paramObj = new Object();
  158.   paramObj.bindingName = bindingName;
  159.   var retStr = extPart.getInsertString("", "Session_DataRef", paramObj);
  160.  
  161.   // We need to strip the cfoutput tags if we are inserting into a CFOUTPUT tag
  162.   // or binding to the attributes of a ColdFusion tag.
  163.   if (dwscripts.canStripCfOutputTags(dropObject, true))
  164.   {
  165.     retStr = dwscripts.stripCFOutputTags(retStr, true);
  166.   } 
  167.  
  168.   return retStr;
  169. }
  170.  
  171.  
  172. //--------------------------------------------------------------------
  173. // FUNCTION:
  174. //   inspectDynamicDataRef
  175. //
  176. // DESCRIPTION:
  177. //   Inspects a dynamic binding string and returns a pair of 
  178. //   source and binding values.
  179. //
  180. // ARGUMENTS:
  181. //   expression - string - the dynamic binding expression to be
  182. //     inspected
  183. //
  184. // RETURNS:
  185. //   JavaScript Array of strings - an array of length 2, with the first
  186. //   value being the sourceName, and the second being the bindingName
  187. //--------------------------------------------------------------------
  188.  
  189. function inspectDynamicDataRef(expression)
  190. {
  191.   var retArray = new Array();
  192.  
  193.   if(expression.length)
  194.   {
  195.     var params = extPart.findInString("Session_DataRef", expression);
  196.     if (params)
  197.     {
  198.       retArray[0] = params.sourceName;
  199.       retArray[1] = params.bindingName;
  200.     }
  201.   }
  202.     
  203.   return retArray;
  204. }
  205.  
  206.  
  207. //--------------------------------------------------------------------
  208. // FUNCTION:
  209. //   deleteDynamicSource
  210. //
  211. // DESCRIPTION:
  212. //   Deletes a dynamic source from the document.
  213. //
  214. // ARGUMENTS:
  215. //   sourceName - string - the name of the dynamic source returned
  216. //     from the findDynamicSources function
  217. //   bindingName - string - the name of a dynamic source binding returned
  218. //     from generateDynamicSourceBindings
  219. //
  220. // RETURNS:
  221. //   nothing
  222. //--------------------------------------------------------------------
  223.  
  224. function deleteDynamicSource(sourceName, bindingName)
  225. {
  226.   var siteURL = dw.getSiteRoot();
  227.       
  228.   if (siteURL.length)
  229.   {
  230.     //For localized object name
  231.     if (sourceName != "Session")
  232.     {
  233.       sourceName = "Session";
  234.     }
  235.  
  236.     dwscripts.deleteListValueFromNote(siteURL, sourceName, bindingName);
  237.   }
  238. }
  239.